#!/bin/bash
## kola:
##   # This test pulls a container from a registry.
##   tags: "platform-independent needs-internet"
##   # This test doesn't make meaningful changes to the system and should
##   # be able to be combined with other tests.
##   exclusive: false
##   # Only run on fcos, as rhel does not support emulation
##   distros: fcos
##   # We ship the x86_64 on all non-x86_64 arches.
##   architectures: "! x86_64"
##   description: Verify the x86_64 qemu emulator works on non-x86_64 instances.

# See https://github.com/coreos/fedora-coreos-tracker/issues/1237

set -xeuo pipefail

# shellcheck disable=SC1091
. "$KOLA_EXT_DATA/commonlib.sh"

case "$(arch)" in
    aarch64|ppc64le|s390x)
        containerArch=$(podman run --arch=amd64 --rm quay.io/fedora/fedora:39 arch)
        if [ "$containerArch" != "x86_64" ]; then
            fatal "Test failed: x86_64 qemu emulator failed to run"
        fi
        ok "Test passed: x86_64 qemu emulator works on $(arch)" ;;
    *)
    # We shouldn't reach this point
    fatal "No qemu-user-static support for $(arch)" ;;
esac
